package ${package}.controller;

import ${package}.com.be.beadmin.device.entity.${className};
import ${package}.dto.output.${className}Ex;
import org.springframework.data.domain.Page;
import com.be.beadmin.common.com.be.beadmin.device.entity.PageEntity;
import ${package}.service.${className}Service;
import ${package}.dto.input.${className}QueryCriteria;
import ${package}.dto.input.${className}Dto;
import org.springframework.data.domain.Pageable;
import com.be.beadmin.common.utils.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.io.IOException;
import java.util.List;
import com.alibaba.excel.EasyExcel;

/**
* @author ${author}
* @date ${date}
**/
@RestController
public class ${className}Controller {

    @Autowired
    private  ${className}Service ${changeClassName}Service;


    @PostMapping(value = "/${apiAlias}/get${className}ByPage")
    public ResultModel get${className}ByPage(@RequestBody PageEntity pageEntity)  {
        return ResultModel.success(${changeClassName}Service.get${className}ByPage(pageEntity)) ;
    }

    @PostMapping("/${apiAlias}/add${className}")
    public ResultModel add${className}(@RequestBody ${className}Dto ${changeClassName}Dto){
        ${changeClassName}Service.add${className}(${changeClassName}Dto);
        return ResultModel.success(ResultModel.ADD);
    }

    @PostMapping("/${apiAlias}/del${className}")
    public ResultModel del${className}(@RequestBody ${className}Dto ${changeClassName}Dto){
        ${changeClassName}Service.del${className}(${changeClassName}Dto.getId());
        return ResultModel.success(ResultModel.DELETE);
    }


    @PostMapping("/${apiAlias}/update${className}")
    public ResultModel update${className}(@RequestBody ${className}Dto ${changeClassName}Dto){
        ${changeClassName}Service.update${className}(${changeClassName}Dto);
        return ResultModel.success(ResultModel.UPDATE);
    }


    @PostMapping("/${apiAlias}/export${className}")
    public void export${className}(HttpServletResponse response ,@RequestBody PageEntity pageEntity) throws IOException {
        Page<${className}Ex> ${changeClassName}Page = ${changeClassName}Service.get${className}ByPage(pageEntity);
        List<${className}Ex> ${changeClassName}Exes = ${changeClassName}Page.getContent();
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("${className}接口", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), ${className}Ex.class).sheet("sheet1").doWrite(${changeClassName}Exes);
    }
}